package com.zdpx.pxframework.security.service;

import com.zdpx.pxframework.core.constant.SecurityConstant;
import com.zdpx.pxframework.core.pojo.LoginUser;
import com.zdpx.pxframework.core.vo.Result;
import com.zdpx.pxframework.auth.api.api.RemoteTokenService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * token业务类
 *
 * @Description:
 * @Author: Cheng XiaoXiao
 * @Date: 2022/2/22  14:22
 */
@Component
public class TokenFrameworkService {

    @Resource
    RemoteTokenService remoteTokenService;

    /**
     * 根据token获取用户信息
     *
     * @param token token
     * @return 登录用户
     */
    public LoginUser getLoginUser(String token) {
        Result<LoginUser> loginUserResult = remoteTokenService.getLoginUserByToken(token, SecurityConstant.INNER);
        return loginUserResult.getData();
    }

    /**
     * 校验token是否过期
     *
     * @param token token
     */
    public void refreshToken(String token) {
        remoteTokenService.refreshToken(token, SecurityConstant.INNER);
    }

    /**
     * 删除用户token
     *
     * @param token 用户标识
     */
    public void deleteToken(String token) {
        remoteTokenService.deleteToken(token, SecurityConstant.INNER);
    }
}
